package com.example.vae.Home.Information;

import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.vae.Adapter.InforItemRecyclerViewAdapter;
import com.example.vae.GuanZhuItemViewModel;
import com.example.vae.R;
import com.example.vae.Utils.RandomString;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class GuanZhuItemFragment extends Fragment {

    private GuanZhuItemViewModel mViewModel;

    public static GuanZhuItemFragment newInstance() {
        return new GuanZhuItemFragment();
    }

    private RecyclerView recyclerView;
    private InforItemRecyclerViewAdapter adapter;

    private List<Integer> imageviews;
    private List<String> names;
    private List<Integer> sexs;


    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {

        View view=inflater.inflate(R.layout.guan_zhu_item_fragment, container, false);
        initdate();

        recyclerView=view.findViewById(R.id.re);
        adapter=new InforItemRecyclerViewAdapter(getContext(),imageviews,names,sexs);

        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        return view;


    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = ViewModelProviders.of(this).get(GuanZhuItemViewModel.class);
        // TODO: Use the ViewModel
    }

//    初始化数据
    public  void initdate(){
        int[] imageRess = new int[]{R.drawable.dongtai_1,R.drawable.dongtai_2,R.drawable.dongtai_3,R.drawable.dongtai_4,R.drawable.find_logo};
        int[] sex=new int[]{R.drawable.boy,R.drawable.woman};
        imageviews=new ArrayList<>();
        names=new ArrayList<>();
        sexs=new ArrayList<>();
        for(int i=0;i<20;i++){
            imageviews.add(imageRess[new Random().nextInt(100) %5]);
            sexs.add(sex[new Random().nextInt(100)%2]);
            names.add(RandomString.getRandomString(8));
        }

    }
}
